﻿using Microsoft.AspNetCore.Mvc.Filters;
using System.Diagnostics;

namespace StarsAdmin.Web.Core.Filter
{
    public class TimeFilter : IAsyncActionFilter
    {
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            // 创建一个计时器
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            await next();
            stopwatch.Stop();
            await Console.Out.WriteLineAsync($"本次执行时长为：{stopwatch.ElapsedMilliseconds}毫秒");
        }
    }
}